﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace JetBlack.Text
{
    internal static class StringExtensions
    {
        static public string ToDelimitedString(this IDictionary<string, object> dictionary)
        {
            return ToDelimitedString(dictionary, ", ");
        }

        static public string ToDelimitedString(this IDictionary<string, object> dictionary, string delimiter)
        {
            return dictionary.ToDelimitedString(",", x => string.Concat(x.Key, ":", x.Value));
        }

        static public string ToDelimitedString<T>(this IEnumerable<T> collection, string delimiter, Func<T, string> toString)
        {
            return string.Join(delimiter, collection.Select(s => toString.Invoke(s)).ToArray());
        }
    }
}
